import Vue from 'vue'
import Router from 'vue-router'

/* Layout */
import Layout from '@/layout'

Vue.use(Router)

/**
 * Note: sub-menu only appear when route children.length >= 1
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: `/`,
    component: Layout,
    redirect: '/organizationalInformationManagement',
    meta: { title: '党员管理', icon: 'system' },
    children: [
      {
        path: `/organizationalInformationManagement`,
        meta: { title: '组织信息管理', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/organizationalInformationManagement/index')
      },
      {
        path: `/teamBuilding`,
        meta: { title: '班子建设', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/teamBuilding/index')
      },
      {
        path: `/partyPositions`,
        meta: { title: '党内职务', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/partyPositions/index')
      },
      {
        path: `/positionLevel`,
        meta: { title: '职位级别', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/positionLevel/index')
      },
      {
        path: `/memberInformationManagement`,
        meta: { title: '党员信息管理', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/memberInformationManagement/index')
      },
      {
        path: `/transferManagement`,
        meta: { title: '组织关系转接管理', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/transferManagement/index')
      },
      {
        path: `/historicalMember`,
        meta: { title: '历史党员', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/historicalMember/index')
      },
      {
        path: `/developmentOfMembers`,
        meta: { title: '党员发展', icon: 'example' },
        component: () => import('@/views/partyMemberManagement/developmentOfMembers/index')
      }
    ]
  },
  {
    path: `/`,
    component: Layout,
    redirect: '/meetingManagement',
    meta: { title: '干部业务', icon: 'system' },
    children: [
      {
        path: `/meetingManagement`,
        meta: { title: '会议管理', icon: 'example' },
        component: () => import('@/views/cadreBusiness/meetingManagement/index')
      },
      {
        path: `/feeAmountManagement`,
        meta: { title: '党费金额管理', icon: 'example' },
        component: () => import('@/views/cadreBusiness/feeAmountManagement/index')
      },
      {
        path: `/feeInfoManagement`,
        meta: { title: '党费信息管理', icon: 'example' },
        component: () => import('@/views/cadreBusiness/feeInfoManagement/index')
      },
      {
        path: `/feeStatistics`,
        meta: { title: '党费统计', icon: 'example' },
        component: () => import('@/views/cadreBusiness/feeStatistics/index')
      },
      {
        path: `/IntegralStatistics`,
        meta: { title: '积分统计', icon: 'example' },
        component: () => import('@/views/cadreBusiness/IntegralStatistics/index')
      },
      {
        path: `/IntegralSettings`,
        meta: { title: '积分设置', icon: 'example' },
        component: () => import('@/views/cadreBusiness/IntegralSettings/index')
      },
      {
        path: `/massAssistance`,
        meta: { title: '群众帮扶', icon: 'example' },
        component: () => import('@/views/cadreBusiness/massAssistance/index')
      },
      {
        path: `/keyPersonnel`,
        meta: { title: '重点人员', icon: 'example' },
        component: () => import('@/views/cadreBusiness/keyPersonnel/index')
      },
      {
        path: `/notice`,
        meta: { title: '通知', icon: 'example' },
        component: () => import('@/views/cadreBusiness/notice/index')
      },
      {
        path: `/remind`,
        meta: { title: '提醒', icon: 'example' },
        component: () => import('@/views/cadreBusiness/remind/index')
      },
      {
        path: `/carouselChart`,
        meta: { title: '轮播图管理', icon: 'example' },
        component: () => import('@/views/cadreBusiness/carouselChart/index')
      }
    ]
  },
  {
    path: `/`,
    component: Layout,
    redirect: '/studyPlatform',
    meta: { title: '在线课堂', icon: 'system' },
    children: [
      {
        path: `/studyPlatform`,
        meta: { title: '学习平台', icon: 'example' },
        component: () => import('@/views/onlineClassroom/studyPlatform/index')
      },
      {
        path: `/partyConstitutionRegulations`,
        meta: { title: '党章党规', icon: 'example' },
        component: () => import('@/views/onlineClassroom/partyConstitutionRegulations/index')
      },
      {
        path: `/partyAffairsKnowledge`,
        meta: { title: '党务知识', icon: 'example' },
        component: () => import('@/views/onlineClassroom/partyAffairsKnowledge/index')
      },
      {
        path: `/studyNotes`,
        meta: { title: '学习笔记', icon: 'example' },
        component: () => import('@/views/onlineClassroom/studyNotes/index')
      }
    ]
  },
  {
    path: `/`,
    component: Layout,
    redirect: '/approvalSetting',
    meta: { title: '审批设置', icon: 'system' },
    children: [
      {
        path: `/approvalSetting`,
        meta: { title: '审批设置', icon: 'example' },
        component: () => import('@/views/designingScheme/approvalSetting/index')
      },
      {
        path: `/designingScheme`,
        meta: { title: '设计方案', icon: 'example' },
        component: () => import('@/views/designingScheme/designingScheme/index')
      },
      {
        path: `/approvalProgress`,
        meta: { title: '审批进展', icon: 'example' },
        component: () => import('@/views/designingScheme/approvalProgress/index')
      },
      {
        path: `/constructionScheme`,
        meta: { title: '施工方案方案', icon: 'example' },
        component: () => import('@/views/constructionScheme/designingScheme/index')
      },
      {
        path: `/constructionScheme/approvalProgress`,
        meta: { title: '审批进展', icon: 'example' },
        component: () => import('@/views/constructionScheme/approvalProgress/index')
      }
    ]
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = (routes, mode) =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: routes || constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
